package com.realtyManage.springboot.Dao;


import com.realtyManage.springboot.Model.Do.BrowseVolume;
import com.realtyManage.springboot.Model.Do.HouseFans;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * 楼盘粉丝
 *
 * @author 杭州素色网络科技有限公司
 * @since 2019-09-24
 */

@Repository
public interface BrowseVolumeRepository extends JpaRepository<BrowseVolume, Integer>, JpaSpecificationExecutor<BrowseVolume> {

    @Query(value="SELECT num FROM browse_volume",nativeQuery=true)
    int getNum();

    @Query(value="SELECT * FROM ((SELECT COUNT(1) ldNum FROM customer_registration WHERE type = 1) a, " +
            "(SELECT num FROM browse_volume) b)",nativeQuery=true)
    String countBrowseVolume();

    @Query(value="SELECT * FROM ((SELECT COUNT(1) ygNum FROM house_detail WHERE type = 4) a, " +
            "(SELECT COUNT(1) wsNum FROM house_detail WHERE type != 4) b, " +
            "(SELECT COUNT(1) rcNum FROM house_detail WHERE type = 1) c, " +
            "(SELECT COUNT(1) tjNum FROM house_detail WHERE special = 1) d) ",nativeQuery=true)
    String countHouseNum();

    @Modifying
    @Transactional
    @Query(value = "UPDATE browse_volume SET num =?1",nativeQuery=true)
    int addNum(Integer value);

    @Query(value="SELECT num FROM external_connection where code = 'importNum'",nativeQuery=true)
    int getImportNum();

    @Modifying
    @Transactional
    @Query(value = "UPDATE external_connection SET num =?1 where code = 'importNum'",nativeQuery=true)
    int addImportNum(Integer value);

    @Query(value="SELECT num FROM external_connection where code = 'distributionNum'",nativeQuery=true)
    int getDistributionNum();

    @Modifying
    @Transactional
    @Query(value = "UPDATE external_connection SET num =?1 where code = 'distributionNum'",nativeQuery=true)
    int addDistributionNum(Integer value);

    @Query(value="SELECT num FROM external_connection where code = 'beltCustomerNum'",nativeQuery=true)
    int getBeltCustomerNum();

    @Modifying
    @Transactional
    @Query(value = "UPDATE external_connection SET num =?1 where code = 'beltCustomerNum'",nativeQuery=true)
    int addBeltCustomerNum(Integer value);

    @Query(value="SELECT num FROM external_connection where code = 'dealNum'",nativeQuery=true)
    int getDealNum();

    @Modifying
    @Transactional
    @Query(value = "UPDATE external_connection SET num =?1 where code = 'dealNum'",nativeQuery=true)
    int addDealNum(Integer value);

}
